import { Controller, Get, Post, Body, Param, Query, Header, Headers } from '@nestjs/common';
import { UsersService } from './users.service';
import { AddAddUserDto, UpdateAddUserDto, QueryUserPageDto } from './users.dto'

@Controller('admin/user')
export class UsersController {
  constructor(private readonly usersService: UsersService) { }

  @Get('info')
  getUserInfo(@Headers('state') state) {
    const { userId } = state
    return this.usersService.getUserInfo(+userId);
  }

  @Post('add')
  addUser(@Body() addAddUserDto: AddAddUserDto) {
    return this.usersService.addUser(addAddUserDto);
  }

  @Post('update')
  updateUser(@Body() updateAddUserDto: UpdateAddUserDto) {
    return this.usersService.updateUser(updateAddUserDto);
  }

  @Post('reset')
  resetUser(@Body('ids') ids: number[]) {
    return this.usersService.resetUser(ids);
  }

  @Post('del/:userId')
  delUser(@Param('userId') userId: string) {
    return this.usersService.delUser(+userId);
  }

  @Get('/:userId')
  getUserById(@Param('userId') userId: string) {
    return this.usersService.getUserById(+userId);
  }

  @Get('page')
  getUserPage(@Query() queryUserPageDto: QueryUserPageDto) {
    return this.usersService.getUserPage(queryUserPageDto);
  }

  @Post('v2/page')
  getUserPageV2(@Body() queryUserPageDto: QueryUserPageDto) {
    return this.usersService.getUserPageV2(queryUserPageDto);
  }

  @Post('getCustomExportTitles')
  getCustomExportTitles() {
    return this.usersService.getCustomExportTitles();
  }

  @Get('getUserOptions')
  getUserOptions() {
    return this.usersService.getUserOptions();
  }
}
